home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / cxref-1.001 / cxref-1~ / cxref / comment.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-24  |  4.3 KB  |  180 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/RCS/comment.c 1.9 1996/02/24 14:50:18 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.0
  5.  
  6.   Collects the comments from the parser.
  7.   ******************/ /******************
  8.   Written by Andrew M. Bishop
  9.  
  10.   This file Copyright 1995,96 Andrew M. Bishop
  11.   It may be distributed under the GNU Public License, version 2, or
  12.   any higher version.  See section COPYING of the GNU Public license
  13.   for conditions under which this file may be redistributed.
  14.   ***************************************/
  15.  
  16. /*+ Turn on the debugging in this file. +*/
  17. #define DEBUG 0
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #include "memory.h"
  24. #include "datatype.h"
  25. #include "cxref.h"
  26.  
  27. /*+ The file that is currently being processed. +*/
  28. extern File CurFile;
  29.  
  30. /*+ The current (latest comment). +*/
  31. static char* cur_comment=NULL;
  32.  
  33. /*+ When in a function or top level of a file, the comment is diverted immediately. +*/
  34. extern int in_function;
  35.  
  36. /*++++++++++++++++++++++++++++++++++++++
  37.   Function that is called when a comment or part of one is seen. The comment is built up until an end of comment is signaled.
  38.  
  39.   char* c The comment text. If c==0 then it is a file (/ * * comment * * /) comment
  40.                             if c==1 then it is the other special comment (/ * + comment + * /).
  41.                             if c==2 then it is a normal comment (/ * comment * /).
  42.                             if c==3 then it is not a comment.
  43.   ++++++++++++++++++++++++++++++++++++++*/
  44.  
  45. void SeenComment(char* c)
  46. {
  47.  static int comment_ended=0;
  48.  
  49.  switch((int)c)
  50.    {
  51.    case 0:
  52. #if DEBUG
  53.     printf("#Comment.c# Seen comment /**\n%s\n**/\n",cur_comment);
  54. #endif
  55.     SeenFileComment(cur_comment); cur_comment=NULL;
  56.     comment_ended=1;
  57.     break;
  58.  
  59.    case 1:
  60. #if DEBUG
  61.     printf("#Comment.c# Seen comment /*+\n%s\n+*/\n",cur_comment);
  62. #endif
  63.     comment_ended=1;
  64.     if(in_function) {SeenFuncIntComment(cur_comment); cur_comment=NULL;}
  65.     break;
  66.  
  67.    case 2:
  68. #if DEBUG
  69.     printf("#Comment.c# Seen comment /*\n%s\n*/\n",cur_comment);
  70. #endif
  71.     comment_ended=1;
  72.     if(!CurFile->comment) {SeenFileComment(cur_comment); cur_comment=NULL;}
  73.     break;
  74.  
  75.    case 3:
  76.     comment_ended=0; cur_comment=NULL;
  77.     break;
  78.  
  79.    default:
  80.     if(comment_ended)
  81.       {comment_ended=0; cur_comment=NULL;}
  82.  
  83.     cur_comment=ConcatStrings(2,cur_comment,c);
  84.    }
  85. }
  86.  
  87.  
  88. /*++++++++++++++++++++++++++++++++++++++
  89.   Provide the current (latest) comment.
  90.  
  91.   char* GetCurrentComment Returns the current (latest) comment.
  92.   ++++++++++++++++++++++++++++++++++++++*/
  93.  
  94. char* GetCurrentComment(void)
  95. {
  96.  char* c=cur_comment;
  97.  
  98. #if DEBUG
  99.     printf("#Comment.c# GetCurrentComment returns <<<%s>>>\n",cur_comment);
  100. #endif
  101.  
  102.  cur_comment=NULL;
  103.  
  104.  return(c);
  105. }
  106.  
  107.  
  108. /*++++++++++++++++++++++++++++++++++++++
  109.   Set the current (latest) comment.
  110.  
  111.   char* comment The comment.
  112.   ++++++++++++++++++++++++++++++++++++++*/
  113.  
  114. void SetCurrentComment(char* comment)
  115. {
  116. #if DEBUG
  117.     printf("#Comment.c# SetCurrentComment set to <<<%s>>>\n",comment);
  118. #endif
  119.  
  120.  cur_comment=comment;
  121. }
  122.  
  123.  
  124. /*++++++++++++++++++++++++++++++++++++++
  125.   A function to split out the arguments etc from a comment, for example the function argument comments are separated using this.
  126.  
  127.   char* SplitComment Returns the required comment.
  128.  
  129.   char** original A pointer to the original comment, this is altered in the process.
  130.  
  131.   char* name The name that is to be cut out from the comment.
  132.  
  133.   A most clever function that ignores spaces so that 'char* b' and 'char *b' match.
  134.   ++++++++++++++++++++++++++++++++++++++*/
  135.  
  136. char* SplitComment(char** original,char* name)
  137. {
  138.  char* c=NULL;
  139.  
  140.  if(*original)
  141.    {
  142.     char* start=*original;
  143.     int l=strlen(name);
  144.  
  145.     while((c=strstr(start,"\n\n")))
  146.       {
  147.        int i,j,failed=0;
  148.  
  149.        for(i=0,j=2;i<l;i++,j++)
  150.          {
  151.           while(name[i]==' ') i++;
  152.           while(c[j]==' ') j++;
  153.  
  154.           if(name[i]!=c[j])
  155.             {failed=1;break;}
  156.          }
  157.  
  158.        if(!failed)
  159.          {
  160.           char* old=*original;
  161.           char* end=strstr(&c[2],"\n\n");
  162.           c[0]=0;
  163.           if(end)
  164.              *original=MallocString(ConcatStrings(2,*original,end));
  165.           else
  166.              *original=MallocString(*original);
  167.           if(end)
  168.              end[0]=0;
  169.           c=MallocString(&c[j+1]);
  170.           Free(old);
  171.           break;
  172.          }
  173.  
  174.        start=&c[2];
  175.       }
  176.    }
  177.  
  178.  return(c);
  179. }
  180.